package cn.tedu;

import java.sql.*;

public class Demo03 {
    public static void main(String[] args) throws SQLException {
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb?characterEncoding=utf8&serverTimezone=Asia/Shanghai","root","breeze123");
        Statement s = conn.createStatement();
        //执行插入数据SQL
//        s.executeUpdate("insert into emp(name) value ('Tom')");
//        s.executeUpdate("update emp set name='Jerry' where name='Tom'");
//        s.executeUpdate("delete from emp where name='Jerry'");
        ResultSet rs = s.executeQuery("select name,sal from emp");
        while(rs.next()){//返回布尔值,判断是否有下一个,并且向下移动游标
//            String name = rs.getString("name");
//            Double sal = rs.getDouble("sal");
            //通过查询回来数据的位置获取数据
            String name = rs.getString(1);
            Double sal = rs.getDouble(2);
            System.out.println(name+":"+sal);
        }
        conn.close();
        System.out.println("执行完成!");
    }
}
